#include"SlideRackPlatform.hpp"
#include "MiscUtils/TdrMisc/SEngine.h"
#include "../GRBLMaster/GRBLMaster.hpp"
#include "Comms/SerialPortManager/SerialPortManager.hpp"

using namespace std;

//GRBLMaster* SlaveNat(void* ptr) {
//	return (GRBLMaster*)ptr;
//};

#define SlaveNat ((GRBLMaster*)_misc.slave)
#define SlaveCommNat ((SerialPortManager*)(((GRBLMaster*)_misc.slave)->_core.slaveNativeHandle))
#define SlaveCommVoid ((GRBLMaster*)_misc.slave)->_core.slaveNativeHandle

SlideRackPlatformSlave::SlideRackPlatformSlave() {
	roboInit();
	_meta.referenceName = L"SlideRackPlatform";
	_meta.model = L"SlideRackPlatform";
	setDefaultFriendlyName();
}

SlideRackPlatformSlave::~SlideRackPlatformSlave() {
	roboRelease();
}

//std::string SlideRackPlatformSlave::State::print() {
//	if (action != nullptr) {
//		string ret;
//		string temp = "?";
//		temp[0] = *action;
//		ret += "Action=[" + temp + "]; ";
//		ret += "Pos=[" + TFormater::floats2str(curXYZABC, 6, -1, 3) + "]; ";
//		ret += "Target=[" + TFormater::floats2str(targetXYZABC, 6, -1, 3) + "]; ";
//		ret += "Limits=[" + TFormater::int2HexStr(*limits, 6) + "]; ";
//		ret += "Homeing=[" + TFormater::int2str(*isHoming) + "]";
//		return ret;
//	}
//	return "";
//}

std::string SlideRackPlatformSlave::getCommBuffer() {
	return SlaveNat->_core.slaveManagerCommBuf;
}

int SlideRackPlatformSlave::moveRack(int rackIndex, float mm) {
	//return SlaveNat->movABC(rackIndex, mm);
	return false;
}

int SlideRackPlatformSlave::moveTransporterX(float mm) {
	return SlaveNat->movHrz(mm);
}

int SlideRackPlatformSlave::moveTransporterZ(float mm) {
	return SlaveNat->movPlatformPerpendicular(mm);
}

float SlideRackPlatformSlave::getTransporterStatusByName(const char* name) {
	return 1;
}
